using Progress.Lang.*.
using OpenEdge.WebSpeed.Request from propath.


routine-level on error undo, throw.



class OpenEdge.WebSpeed.Filters.Actional:

	define variable actionalEnabled    as logical    init ? no-undo.
	define variable actionalUrl        as character  no-undo.
	define variable actionalGroup      as character  no-undo.
	define variable actionalService    as character  no-undo.
	define variable actionalSI         as class      actional.ServerInteraction.

	
	constructor public Actional().
	
	end constructor.
	
	method public void InitRequest (input request as Request).
	
       	define variable tmpChr1            as character  no-undo.
		define variable tmpChr             as character  no-undo.
		define variable tmpInt             as integer    no-undo.


		if actionalEnabled = ? then do:
		    if lookup("-ACTIONALENABLED", session:startup-parameters) <> 0 then
		      actionalEnabled = true.
		    else
		      actionalEnabled = false.
		
		    /* setup Actional information */
		    if actionalEnabled then do:
/*		    dynamic-function("logNote":U in web-utilities-hdl, "ACTIONAL", "Initializing Actional").*/
		      /* setup defaults */
		      actionalGroup = "OpenEdge".
		      actionalService = "wsbroker".
		
		      /* setup group and service name from command-line switch */
		      tmpInt = index(session:startup-parameters,"-ACTIONALGROUP").
		      if tmpInt <> 0 then do:
		
		        /* switch was specified, get the parameter */
		        tmpChr = substring(session:startup-parameters, tmpInt).
		        tmpChr = entry(1, tmpChr).
		        tmpChr = trim(substring(tmpChr, length("-ACTIONALGROUP "))).
		
		        /* parameter is  <group name>:<service name> */
		        if index(tmpChr, ":") <> 0 then do:
		
		          /* get the group name */
		          tmpChr1 = entry(1, tmpChr, ":").
		          if length(tmpChr1) <> 0 then
		            actionalGroup = tmpChr1.
		
		          /* get the service name */
		          tmpChr1 = entry(2, tmpChr, ":").
		          if length(tmpChr1) <> 0 then
		            actionalService = tmpChr1.
		        end.
		        else do:
		          /* no separator was specified, */
		          /* parameter is the group name */
		          actionalGroup = tmpChr.
		        end.
		      end.
		      actionalUrl = "OpenEdge://":U + request:ServerName + "/WebSpeed/":U + actionalService.
/*		      dynamic-function("logNote":U in web-utilities-hdl, "ACTIONAL":U, "Actional URL: " + actionalUrl).        */
/*		      dynamic-function("logNote":U in web-utilities-hdl, "ACTIONAL":U, "Actional Group: " + actionalGroup).    */
/*		      dynamic-function("logNote":U in web-utilities-hdl, "ACTIONAL":U, "Actional Service: " + actionalService).*/
		    end.
		  end.
		    
		  if actionalEnabled then do:
/*		    dynamic-function("logNote":U in web-utilities-hdl, "ACTIONAL":U, "Creating new ServerInteraction").*/
		    actionalSI = new actional.ServerInteraction().
		    actionalSI:Begin().
		    actionalSI:SetUrl(actionalUrl).
		    actionalSI:SetPeerAddr(request:RemoteHost).
		    actionalSI:SetGroupName(actionalGroup).
		    actionalSI:SetAppType(actional.ServerInteraction:ACT_DT_OEGROUP).
		    actionalSI:SetServiceName(actionalService).
		    actionalSI:SetSvcType(actional.ServerInteraction:ACT_DT_WEBSPEED).
		    actionalSI:SetOpName(request:AppProgram).
		    actionalSI:RequestAnalyzed().
		  end.    
    
	end.
	
	method public void EndRequest (input request as Request).
	      /* Done with Actional */
	  if actionalEnabled then do:
/*	    dynamic-function("logNote":U in web-utilities-hdl, "ACTIONAL":U, "ServerInteraction completed for operation " + request:AppProgram).*/
	    actionalSI:end().
	    actionalSI:freeSInteraction().
	    delete object actionalSI.
	  end.
    
	
	
	end method.


end class.